package day2;

import org.junit.Test;

import java.util.Random;
import java.util.Scanner;

public class ContinueBreakTest {
//  continue：跳出本次循环，继续下一次循环
//  break：跳出离他最近的那层循环
    @Test
    public void test1() {
        for (int i = 1; i <= 10; i++) {
            if (i == 5) {
                continue;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test2() {
        for (int i = 1; i <= 10; i++) {
            if (i == 5) {
                break;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test3() {
        for (int i = 1; i <= 10; i++) {
            for (int j = 1; j <= 10; j++) {
                if (j == 5) {
                    break;
                }
                System.out.println("j: " + j);
            }
            System.out.println("i: " + i);

        }
    }

    public static void main(String[] args) {

    }
    //例题：随机生成一个整数1-1000
    @Test
    public void test11() {
        Scanner scanner = new Scanner(System.in);
        //Random random = new Random();
        // param:parameter 参数   arg:argument
        // int value between 0 (inclusive) and the specified value (exclusive)
        // [0,1000) + 1
        // [0,999] + 1 = [1,1000]
        int random = new Random().nextInt(1000) + 1;
        System.out.println(random);
        // for (;;) { }
        // Unreachable statement
        while (true) {
            System.out.println("猜吧！");
            int guess = scanner.nextInt();
            if (guess > random) {
                System.out.println("太大了");
            } else if (guess < random) {
                System.out.println("太小了");
            } else {
                System.out.println("恭喜你，猜对了");
                break;
            }
        }

        System.out.println("程序结束");
    }




}
